package com.boot2523.control;

import com.boot2523.bean.User;
import com.boot2523.service.UserRedisS;
import com.boot2523.service.UserRedisS2;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "user")
public class UserC {
    @Resource
    public UserRedisS us;
//    @PostMapping(value = "/insert")
    @PostMapping
    public String insert(@RequestBody  User u){
        us.save(u);
        return "添加成功";
    }

    /**
     * @@PathVariable为路径变量注解，是一个参数注解,将路径中的参数传递给形参
     * user/1
     * user/21
     * @param key
     * @return
     */
    @GetMapping(value = "/{key}")
    public Object one(@PathVariable String key){
        return us.get(key);
    }
    @DeleteMapping(value = "/{key}")
    public String del(@PathVariable String key){
        us.delete(key);
        return "删除成功";
    }
    @GetMapping(value = "/all")
    public List<Object> all(String key){
        return us.find(key);
    }
    @Resource
    public UserRedisS2 us2;
    @GetMapping(value = "/one/{key}")
    public User getUser(@PathVariable  String key){
        return us2.get(key);
    }
}
